package cc.bukkitPlugin.banitem.command;

import java.util.ArrayList;

import org.bukkit.command.CommandSender;

import cc.bukkitPlugin.banitem.CFG;
import cc.bukkitPlugin.banitem.command.analyse.AParam;

public class CommandParam extends AParamCommand{

    private ArrayList<String> mSubCommand=new ArrayList<>();
    private ArrayList<AParam> mModels=new ArrayList<>();

    public CommandParam(CommandExc pExector){
        super(pExector,"param");
        this.mSubCommand.addAll(this.mAnalyseMan.keySet());
        this.mModels.addAll(this.mAnalyseMan.valueSet());
    }

    @Override
    public boolean execute(CommandSender pSender,String pLabel,String[] pArgs){
        if(!pSender.hasPermission(this.mPluginName+".viewparam"))
            return noPermission(pSender);
        if(pArgs.length==0)
            return send(pSender,this.mAnalyseMan.getHelp());
        if(pArgs.length==1){
            AParam tModel=this.mAnalyseMan.getParamModel(pArgs[0]);
            if(tModel==null)
                return send(pSender,"&c不存在使用["+pArgs[0]+"]标签的参数模块");
            else return send(pSender,tModel.getHelp());
        }else return help(pSender,pLabel);
    }

    @Override
    public ArrayList<String> getHelp(CommandSender pSender,String pLabel){
        ArrayList<String> list=new ArrayList<>();
        if(pSender.hasPermission(this.mPluginName+".viewparam")){
            list.add(CFG.cmd_color+this.mMainCmdLabel+" param [参数标签]");
            list.add(CFG.help_color+"获取插件命令参数的说明");
        }
        return list;
    }

    @Override
    public ArrayList<String> getSubCommand(CommandSender pSender,String pLabel,String[] pArgs){
        ArrayList<String> subCopy=new ArrayList<>(this.mSubCommand.size());
        subCopy.addAll(this.mSubCommand);
        return subCopy;
    }

    @Override
    public int getMaxArgumentLength(String pLabel){
        return 2;
    }

    @Override
    public boolean isParamAllow(Class<? extends AParam> pClazzModel){
        return true;
    }

}
